import 'dart:io';

import 'package:flutter/material.dart';

import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:leader_help/value/topcolors.dart';

import 'logic.dart';

class FeedbackPage extends StatelessWidget {
  final logic = Get.put(FeedbackLogic());
  final state = Get.find<FeedbackLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(leading: BackButton(color: Colors.white,),title: Text('意见反馈',style: TextStyle(color: Colors.white,fontSize: 18.sp)),elevation: 0,centerTitle: true,backgroundColor: TopColors.main_red,) ,
        body: Column(children: [
          Expanded(child: CustomScrollView(
            physics: BouncingScrollPhysics(),
            slivers: [
              SliverToBoxAdapter(child: Container(child: Column(children: [
                Container(child: Text('填写问题描述',style: TextStyle(color: TopColors.black_33,fontSize: 14.sp),),margin: EdgeInsets.only(top: 10,bottom: 5),),
                Container(child: TextField(controller:state.contentTextEditingController,decoration: InputDecoration(border: InputBorder.none,hintText: '请输入您遇到的问题'),maxLength: 100,minLines: 4,maxLines: 5,style: TextStyle(fontSize: 14),),),
              ],crossAxisAlignment: CrossAxisAlignment.start,),color: Colors.white,margin: EdgeInsets.only(bottom: 10),padding: EdgeInsets.all(15)),),

              SliverToBoxAdapter(child: Container(child: Column(children: [
                Container(child: Text('上传图片',style: TextStyle(color: TopColors.black_66,fontSize: 14.sp),),margin: EdgeInsets.only(top: 20,bottom: 5),) ,
                Visibility(child:GestureDetector(child: Container(child: Icon(Icons.add_a_photo_outlined,color: Colors.grey,size: 50,),margin: EdgeInsets.all(15),width: 80,height: 80,decoration: BoxDecoration(border: Border.all(color: Colors.grey,width: 1)),),onTap: logic.selectImages,),visible: state.listImagePaths.length==0,),

                Visibility(child: Container(child: MediaQuery.removePadding(context: context,removeTop: true, child: GridView.builder(gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                  crossAxisCount: 3,
                  crossAxisSpacing: 10,
                  mainAxisSpacing: 10,
                  childAspectRatio: 1,
                ), itemBuilder: (context,index){
                  return GestureDetector(child: Container(child: itemImageLayout(index),color: Colors.white,),onTap: (){
                    // Navigator.push(context, MaterialPageRoute(builder: (context)=>TalkTagDetailPage(recommendBeanEntity.issue[index].issueId)));
                  },);
                },itemCount: state.listImagePaths.length,shrinkWrap: true,physics: NeverScrollableScrollPhysics())),margin: EdgeInsets.only(top: 15,bottom: 15),),visible: state.listImagePaths.length>0,),



              ],crossAxisAlignment: CrossAxisAlignment.start),color: Colors.white,margin: EdgeInsets.only(bottom: 10),padding: EdgeInsets.all(15),width: MediaQuery.of(context).size.width,),),
            ],),
          ),

          GestureDetector(child: Container(child: Container(child: Center(child: Text('提交意见',style: TextStyle(color: TopColors.tx_baoming,fontWeight: FontWeight.bold),),),decoration: BoxDecoration(gradient: LinearGradient(
            begin: Alignment.topCenter,
            end: Alignment.bottomCenter,
            colors: [
              Color(0xffF3DBB6),
              Color(0xffCBA76D),
            ],
          ),borderRadius: BorderRadius.all(Radius.circular(4))),padding: EdgeInsets.fromLTRB(15, 8, 15, 8),width: MediaQuery.of(context).size.width-40,),padding: EdgeInsets.all(10),color: Colors.white,width: MediaQuery.of(context).size.width,),onTap: logic.putData),
        ]));
  }
    Widget itemImageLayout(int index){
      return Stack(children: [
        Image.file(File(state.listImagePaths[index].path!),fit: BoxFit.cover,width: 120,height: 120,),

        GestureDetector(child: Align(child: Icon(Icons.cancel,color: Colors.black,size: 20,),alignment: Alignment.topRight,),onTap: (){
          logic.deletePic(index);
        },)
      ],);
    }
}


